Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.IO
Public Class clsManejadorDatos
    Public Function objExecuteReader(ByVal SQL As String, ByVal MyTrans As SqlTransaction, ByVal Cn As SqlConnection, _
                                    Optional ByVal Time As Integer = 0, _
                                    Optional ByVal CMD As SqlCommand = Nothing) As SqlDataReader

        Try
            Dim Reader As SqlDataReader


            If SQL <> String.Empty Then
                CMD = New SqlCommand(SQL, Cn)
            End If


            CMD.Transaction = MyTrans

            If Time > 1 Then
                CMD.CommandTimeout = Time
            End If
            'CMD.CommandType = Data.CommandType.Text
            Reader = CMD.ExecuteReader
            CMD = Nothing
            Return Reader
            Reader = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function objExecuteQuery(ByVal SQL As String, ByVal MyTrans As SqlTransaction, ByVal Cn As SqlConnection, _
                                    Optional ByVal CMD As SqlCommand = Nothing) As Long

        Try

            If SQL <> String.Empty Then
                CMD = New SqlCommand(SQL, Cn)
            End If

            cmd.Transaction = MyTrans
            cmd.ExecuteNonQuery()
            cmd = Nothing
            Return 1
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function obj_UpFiles(ByVal FleArchivo As FileUpload, ByVal ImgRuta As String, Optional ByVal NewFileName As String = "") As Boolean

        Try
            Dim Exist As Boolean
            Dim RutNewFileName As String = ImgRuta
            System.IO.Directory.CreateDirectory(ImgRuta)

	    If NewFileName <> String.Empty Then
		ImgRuta += "\" & Replace(Path.GetFileName(FleArchivo.FileName)," ","")
	    Else
		ImgRuta += "\" & Path.GetFileName(FleArchivo.FileName)				
	    END IF


            If FleArchivo.HasFile Then

                If System.IO.File.Exists(ImgRuta) = False Then

                    If NewFileName = String.Empty Then
                        FleArchivo.PostedFile.SaveAs(ImgRuta)
                    Else
                        FleArchivo.PostedFile.SaveAs(RutNewFileName & "\" & NewFileName)
                    End If

                    Exist = False
                Else
                    Exist = True
                End If
            End If
            Return Exist
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function objExecuteStoreProcedure(ByVal CMD As SqlCommand, _
                    ByVal MyTrans As SqlTransaction, ByVal Cn As SqlConnection) As SqlDataReader

        CMD.CommandType = Data.CommandType.StoredProcedure
        CMD.Transaction = MyTrans
        Dim Reader As SqlDataReader = CMD.ExecuteReader
        Return Reader

    End Function
End Class
